import 'package:flutter/material.dart';

class OnScreenWidget extends ModalRoute<dynamic> {
  Widget child;
  bool? willPopSecond;
  @override
  Color? barrierColor = Colors.black.withOpacity(0.5);
  bool? willPopFlag;

  OnScreenWidget(this.child,
      {this.barrierColor = const Color.fromRGBO(0, 0, 0, 0.5),
      this.willPopSecond = false,
      this.willPopFlag = true});

  @override
  Duration get transitionDuration => const Duration(milliseconds: 200);

  @override
  bool get opaque => false;

  @override
  bool get barrierDismissible => false;

  @override
  String? get barrierLabel => null;

  @override
  bool get maintainState => true;

  @override
  Widget buildPage(
    BuildContext context,
    Animation<double> animation,
    Animation<double> secondaryAnimation,
  ) {
    return Material(
      type: MaterialType.transparency,
      child: (Scaffold(
        body: child,
        backgroundColor: Colors.transparent,
      )),
    );
  }

  @override
  Widget buildTransitions(BuildContext context, Animation<double> animation,
      Animation<double> secondaryAnimation, Widget child) {
    return FadeTransition(
      opacity: animation,
      child: ScaleTransition(
        scale: animation,
        child: child,
      ),
    );
  }
}
